#!/data/data/com.termux/files/usr/bin/bash -e
unset LD_PRELOAD
if [ ! -f /data/data/com.termux/files/home/kali-arm64/root/.version ]; then
    touch /data/data/com.termux/files/home/kali-arm64/root/.version
fi
user=kali
home="/home/$user"
LOGIN="sudo -u $user /bin/bash"
if [[ ("$#" != "0" && ("$1" == "-r")) ]]; then
    user=root
    home=/$user
    LOGIN="/bin/bash --login"
    shift
fi

cmd="proot \
    --link2symlink \
    -0 \
    -r /data/data/com.termux/files/home/kali-arm64 \
    -b /dev \
    -b /proc \
    -b /data/data/com.termux/files/home/clone/B/proc/stat:/proc/stat \
    -b /data/data/com.termux/files/home/clone/B/proc/uptime:/proc/uptime \
    -b /data/data/com.termux/files/home/clone/B/proc/version:/proc/version \
    -b /data/data/com.termux/files/home/clone/B/proc/locdavg:/proc/locdavg \
    -b /data/data/com.termux/files/home/clone/B/proc/filesystems:/proc/filesystems \
    -b /data/data/com.termux/files/home/kali-arm64$home:/dev/shm \
    -b /sdcard \
    -b /data/data/com.termux/files/home \
    -w $home \
    /usr/bin/env -i \
    HOME=$home TERM="$TERM" \
    LANG=$LANG PATH=/bin:/usr/bin:/sbin:/usr/sbin \
    $LOGIN"

args="$@"
if [ "$#" == 0 ]; then
    exec $cmd
else
    $cmd -c "$args"
fi
